*******************************************************************
* This file generates all results based on the Cartoon Crisis
* in the main paper and online appendix
*
* Table 6-8, Figures 3-4, Appendix D
*******************************************************************

cd "${data_dir}"
use hierarchy_cartoon_data.dta, clear
xtset firmcode aar

cd "${results_dir}"

* Event Study: High Risk Sample 
foreach var in layers loginequality4 ///
loginequality1 wagegap3_topbottom_log {

areg `var' ///
Arab20052002 ///
Arab20052003 Arab20052004 ///
Arab20052006 Arab20052007 ///
year2002-year2007 treatment_trend ///
if year > 2000 & year < 2008 ///
& highrisksample == 1, ///
absorb(firmcode) vce(cluster sector027)

estimates save "event_`var'", replace

outreg2 using TableA36.tex, ///
tex alpha(0.01, 0.05, 0.1) symbol(***,**,*) bdec(4) ///
keep(Arab20052002 ///
Arab20052003 Arab20052004 ///
Arab20052006 Arab20052007) ///
adds("Firms", e(df_a)+1) append
}


* Long Event Study: High Risk Sample 
foreach var in layers loginequality4 ///
loginequality1 wagegap3_topbottom_log {

areg `var' ///
Arab20052002 ///
Arab20052003 Arab20052004 ///
Arab20052006 Arab20052007 Arab20052008 ///
year2002-year2008 treatment_trend ///
if year > 2000 & year <= 2008 ///
& highrisksample == 1, ///
absorb(firmcode) vce(cluster sector027)

estimates save "event_`var'_long", replace

outreg2 using TableA38.tex, ///
tex alpha(0.01, 0.05, 0.1) symbol(***,**,*) bdec(4) ///
keep(Arab20052002 ///
Arab20052003 Arab20052004 ///
Arab20052006 Arab20052007 Arab20052008) ///
adds("Firms", e(df_a)+1) append
}

* Pooled Results: High risk sample
set more off
foreach var in layers wagegap3_topbottom_log {
areg `var' year2002-year2006 treatment_trend ///
Arab20052006 ///
if year > 2000 & year < 2007 ///
& highrisksample == 1, ///
absorb(firmcode) vce(cluster sector027)

outreg2 using Table6.tex, ///
tex alpha(0.01, 0.05, 0.1) symbol(***,**,*) bdec(4) ///
keep(Arab20052006) adds("Firms", e(df_a)+1) append
}
foreach var in loginequality1 loginequality2 loginequality4 loginequality5 {
areg `var' year2002-year2006 ///
Arab20052006 ///
if year > 2000 & year < 2007 ///
& highrisksample == 1, ///
absorb(firmcode) vce(cluster sector027)

outreg2 using Table6.tex, ///
tex alpha(0.01, 0.05, 0.1) symbol(***,**,*) bdec(4) ///
keep(Arab20052006) adds("Firms", e(df_a)+1) append
}

* Pooled Results: Full sample
set more off
foreach var in logsales_usd layers wagegap3_topbottom_log {
areg `var' year2002-year2006 treatment_trend ///
Arab20052006 ///
if year > 2000 & year < 2007 ///
& fullsample == 1, absorb(firmcode) vce(cluster sector027)

outreg2 using TableA43.tex, ///
tex alpha(0.01, 0.05, 0.1) symbol(***,**,*) bdec(4) ///
keep(Arab20052006) adds("Firms", e(df_a)+1) append
}
foreach var in loginequality1 loginequality2 loginequality4 loginequality5 {
areg `var' year2002-year2006 ///
Arab20052006 ///
if year > 2000 & year < 2007 ///
& fullsample == 1, absorb(firmcode) vce(cluster sector027)

outreg2 using TableA43.tex, ///
tex alpha(0.01, 0.05, 0.1) symbol(***,**,*) bdec(4) ///
keep(Arab20052006) adds("Firms", e(df_a)+1) append
}


* Add indicator for actually dropped layers:
**************************************************

set more off
foreach var in wagegap3_topbottom_log loginequality1 ///
loginequality2 loginequality4 loginequality5 {
areg `var' year2002-year2006 treatment_trend ///
Arab20052006 c.Arab20052006#c.droplayers ///
if year > 2000 & year < 2007 ///
& fullsample == 1, absorb(firmcode) vce(cluster sector027)

outreg2 using TableA44.tex, ///
tex alpha(0.01, 0.05, 0.1) symbol(***,**,*) bdec(4) ///
keep(Arab20052006 c.Arab20052006#c.droplayers) adds("Firms", e(df_a)+1) append
}

* Ordered logit as robustness for the boycott effect:
ologit layerchange year2002-year2007 treatment Arab20052006 ///
if year > 2000 & year < 2007 & fullsample == 1, vce(cluster sector027)

outreg2 using TableA45.tex, ///
tex alpha(0.01, 0.05, 0.1) symbol(***,**,*) bdec(4) ///
keep(treatment Arab20052006) replace

ologit layerchange year2002-year2007 i.sector053 ///
L.logsales_usd L.logempl L.i.layers treatment Arab20052006 ///
if year > 2000 & year < 2007 & fullsample == 1, vce(cluster sector027)

outreg2 using TableA45.tex, ///
tex alpha(0.01, 0.05, 0.1) symbol(***,**,*) bdec(4) ///
keep(treatment Arab20052006) append

ologit layerchange year2002-year2008 treatment Arab20052006 Arab20052007 ///
if year > 2000 & year < 2008 & fullsample == 1, vce(cluster sector027)

outreg2 using TableA45.tex, ///
tex alpha(0.01, 0.05, 0.1) symbol(***,**,*) bdec(4) ///
keep(treatment Arab20052006 Arab20052007) append

ologit layerchange year2002-year2008 i.sector053 ///
L.logsales_usd L.logempl L.i.layers treatment Arab20052006 Arab20052007 ///
if year > 2000 & year < 2008 & fullsample == 1, vce(cluster sector027)

outreg2 using TableA45.tex, ///
tex alpha(0.01, 0.05, 0.1) symbol(***,**,*) bdec(4) ///
keep(treatment Arab20052006 Arab20052007) append



preserve

local titlelist " "Layers" "Standard Deviation of Wages" "90-50 Wage Gap" "Top-to-Bottom-Layer Wage Gap" "
local ytitlelist " "Number of Layers" "SD(Log Wages)" "90-50 Log Wage Gap" "Wage Gap Between Top and Bottom Layer" "

local j = 1
foreach var in layers loginequality1 loginequality4 wagegap3_topbottom_log {

local title : word `j' of `titlelist'
local ytitle : word `j' of `ytitlelist'

clear
estimates use "event_`var'"

matrix define lambda = e(b)
matrix define lambdase = e(V)

matrix lambdase2 = vecdiag(lambdase)

matrix param = [lambda[1,1..5]]'
matrix paramse = [lambdase2[1,1..5]]'

svmat param
svmat paramse

gen year = _n
replace year = year + 2001 if _n<=3
replace year = year + 2002 if _n>3

expand 2 in 3

sort year

replace param1 = 0 if year == 2004 & year[_n-1]==2004
replace paramse1 = 0 if year == 2004 & year[_n-1]==2004
replace year = 2005 if year == 2004 & year[_n-1]==2004

replace paramse1 = sqrt(paramse1)
gen ci_up = param1 + (paramse1*1.64)
gen ci_low = param1 - (paramse1*1.64)

twoway (scatter param1 year, connect(l)) ///
(rcap ci_up ci_low year), ///
xline(2005.5, lpattern(dash) lcolor(black)) ///
yline(0, lpattern(dash) lcolor(black)) ///
legend(off) xtitle(Year) graphregion(color(white)) ///
title(`title') ytitle(`ytitle')

graph export Figure3_event_`var'.pdf, replace

local j = `j'+1
}
restore

preserve

local titlelist " "Layers" "Standard Deviation of Wages" "90-50 Wage Gap" "Top-to-Bottom-Layer Wage Gap" "
local ytitlelist " "Number of Layers" "SD(Log Wages)" "90-50 Log Wage Gap" "Wage Gap Between Top and Bottom Layer" "

local j = 1
foreach var in layers loginequality1 loginequality4 wagegap3_topbottom_log {

local title : word `j' of `titlelist'
local ytitle : word `j' of `ytitlelist'

clear
estimates use "event_`var'_long"

matrix define lambda = e(b)
matrix define lambdase = e(V)

matrix lambdase2 = vecdiag(lambdase)

matrix param = [lambda[1,1..6]]'
matrix paramse = [lambdase2[1,1..6]]'


svmat param
svmat paramse

gen year = _n
replace year = year + 2001 if _n<=3
replace year = year + 2002 if _n>3

expand 2 in 3

sort year

replace param1 = 0 if year == 2004 & year[_n-1]==2004
replace paramse1 = 0 if year == 2004 & year[_n-1]==2004
replace year = 2005 if year == 2004 & year[_n-1]==2004

replace paramse1 = sqrt(paramse1)
gen ci_up = param1 + (paramse1*1.64)
gen ci_low = param1 - (paramse1*1.64)

twoway (scatter param1 year, connect(l)) ///
(rcap ci_up ci_low year), ///
xline(2005.5, lpattern(dash) lcolor(black)) ///
yline(0, lpattern(dash) lcolor(black)) ///
legend(off) xtitle(Year) graphregion(color(white)) ///
title(`title') ytitle(`ytitle')

graph export FigureA7_`var'.pdf, replace

local j = `j'+1
}

restore


* Robustness to Importing and Import Competition
cd "${data_dir}"
merge 1:1 aar cvrnr using imports_china.dta
drop if _merge == 2
drop _merge

merge 1:1 aar cvrnr using importpenetration_china.dta
drop if _merge == 2
drop _merge

cd "$results_dir}"

* own importing activity
* Create control variables for import competition:
gen implevelhelp = log(1+imports) if aar == 2005
sort cvrnr aar
by cvrnr: egen implevel2005 = max(implevelhelp)
replace implevel2005 = 0 if implevel2005 == .

forvalues x = 2001/2008 {
gen implevel_year`x' = implevel2005 * (aar == `x')
}
gen implevel_trend = implevel2005 * (aar - 2000)

gen shareimp = imports / sales_usd
replace shareimp = 0 if shareimp == .
replace shareimp = 1 if shareimp > 0 & shareimp !=.
gen imphelp = shareimp if aar == 2005
sort cvrnr aar
by cvrnr: egen impshare2005 = max(imphelp)
replace impshare2005 = 0 if impshare2005 == .

forvalues x = 2001/2008 {
gen impshare_year`x' = impshare2005 * (aar == `x')
}
gen impshare_trend = impshare2005 * (aar - 2000)


* Chinese import penetration measure by firm in 2005:
gen impcomphelp = impshare_china if aar == 2005
sort cvrnr aar
by cvrnr: egen firmimpcomp = max(impcomphelp)
replace firmimpcomp = 0 if firmimpcomp == .

forvalues x = 2001/2008 {
gen firmimpcomp_year`x' = firmimpcomp * (aar == `x')
}
gen firmimpcomp_trend = firmimpcomp * (aar - 2000)

cap drop impcomphelp
gen impcomphelp = implevel_china/10 if aar == 2005
sort cvrnr aar
by cvrnr: egen firmimpcomplevel = max(impcomphelp)
replace firmimpcomplevel = 0 if firmimpcomplevel == .

forvalues x = 2001/2008 {
gen firmimpcomplevel_year`x' = firmimpcomplevel * (aar == `x')
}
gen firmimpcomplevel_trend = firmimpcomplevel * (aar - 2000)

* Importance of imports from China by firm in 2005
replace imp_china = 0 if imp_china == .
gen logimp_china = log(1+imp_china)
gen shareimp_china = imp_china / imports

gen Chinahelp = shareimp_china if aar == 2005
sort cvrnr aar
by cvrnr: egen Chinashare = max(Chinahelp)
replace Chinashare = 0 if Chinashare == .

gen treatment_china = 0
replace treatment_china = 1 if Chinashare >0 & Chinashare != .

forvalues x = 2001/2008 {
gen china_year`x' = treatment_china * (aar == `x')
}
forvalues x = 2001/2008 {
gen chinashare_year`x' = Chinashare * (aar == `x')
}
gen china_trend = treatment_china * (aar - 2000)
gen chinashare_trend = Chinashare * (aar - 2000)

foreach control in implevel impshare china chinashare {
foreach var in layers loginequality1 loginequality4 wagegap3_topbottom_log {
areg `var' ///
Arab20052002 ///
Arab20052003 Arab20052004 ///
Arab20052006 Arab20052007 ///
`control'_year2002-`control'_year2004 `control'_year2006-`control'_year2007 ///
year2002-year2007 treatment_trend `control'_trend ///
if year > 2000 & year <= 2007 & highrisksample == 1, ///
absorb(firmcode) vce(cluster sector027)

estimates save "event_`var'_`control'", replace

outreg2 using TableA40_`control'.tex, ///
tex alpha(0.01, 0.05, 0.1) symbol(***,**,*) bdec(4) ///
keep(Arab20052006) adds("Firms", e(df_a)+1) append

}

}

foreach control in firmimpcomp firmimpcomplevel {
foreach var in layers loginequality1 loginequality4 wagegap3_topbottom_log {
areg `var' ///
Arab20052002 ///
Arab20052003 Arab20052004 ///
Arab20052006 Arab20052007 ///
`control'_year2002-`control'_year2004 `control'_year2006-`control'_year2007 ///
year2002-year2007 treatment_trend `control'_trend ///
if year > 2000 & year <= 2007 & highrisksample == 1, ///
absorb(firmcode) vce(cluster sector027)

estimates save "event_`var'_`control'", replace

outreg2 using TableA41_`control'.tex, ///
tex alpha(0.01, 0.05, 0.1) symbol(***,**,*) bdec(4) ///
keep(Arab20052006) adds("Firms", e(df_a)+1) append

}

}


preserve
local titlelist " "Layers" "90-50 Wage Gap" "
local ytitlelist " "Number of Layers" "90-50 Log Wage Gap" "
local controllist " "Log(1+Imports)" "Import Share of Sales" "

local k = 1
foreach set in implevel impshare {
local j = 1
foreach var in layers loginequality4 {

local title : word `j' of `titlelist'
local ytitle : word `j' of `ytitlelist'
local ctitle : word `k' of `controllist'

clear
estimates use "event_`var'_`set'"

matrix define lambda = e(b)
matrix define lambdase = e(V)

matrix lambdase2 = vecdiag(lambdase)

matrix param = [lambda[1,1..5]]'
matrix paramse = [lambdase2[1,1..5]]'
matrix param2 = [lambda[1,6..10]]'
matrix paramse2 = [lambdase2[1,6..10]]'

svmat param
svmat paramse
svmat param2
svmat paramse2

gen year = _n
replace year = year + 2001 if _n<=3
replace year = year + 2002 if _n>3

expand 2 in 3

sort year

replace param1 = 0 if year == 2004 & year[_n-1]==2004
replace paramse1 = 0 if year == 2004 & year[_n-1]==2004
replace param2 = 0 if year == 2004 & year[_n-1]==2004
replace paramse2 = 0 if year == 2004 & year[_n-1]==2004
replace year = 2005 if year == 2004 & year[_n-1]==2004

replace paramse1 = sqrt(paramse1)
gen ci_up = param1 + (paramse1*1.64)
gen ci_low = param1 - (paramse1*1.64)

replace paramse2 = sqrt(paramse2)
gen ci_up2 = param2 + (paramse2*1.64)
gen ci_low2 = param2 - (paramse2*1.64)

gen year2 = year + 0.1

twoway (scatter param1 year, connect(l) color(gs4)) ///
(rcap ci_up ci_low year, color(gs4)) ///
(scatter param2 year2, connect(l) color(gs12)) ///
(rcap ci_up2 ci_low2 year2, color(gs12)), ///
xline(2005.5, lpattern(dash) lcolor(black)) ///
yline(0, lpattern(dash) lcolor(black)) ///
legend(order(1 3) label(1 "Any Muslim Exposure") label(3 "`ctitle'")) ///
xtitle(Year) graphregion(color(white)) ///
title(`title') ytitle(`ytitle')

graph export FigureA11_`var'_`set'.pdf, replace

local j = `j'+1
}
local k = `k'+1
}

restore

preserve
local titlelist " "Layers" "90-50 Wage Gap" "
local ytitlelist " "Number of Layers" "90-50 Log Wage Gap" "
local controllist " "Any Imports from China" "Share of Imports from China" "

local k = 1
foreach set in china chinashare {
local j = 1
foreach var in layers loginequality4 {

local title : word `j' of `titlelist'
local ytitle : word `j' of `ytitlelist'
local ctitle : word `k' of `controllist'

clear
estimates use "event_`var'_`set'"

matrix define lambda = e(b)
matrix define lambdase = e(V)

matrix lambdase2 = vecdiag(lambdase)

matrix param = [lambda[1,1..5]]'
matrix paramse = [lambdase2[1,1..5]]'
matrix param2 = [lambda[1,6..10]]'
matrix paramse2 = [lambdase2[1,6..10]]'

svmat param
svmat paramse
svmat param2
svmat paramse2

gen year = _n
replace year = year + 2001 if _n<=3
replace year = year + 2002 if _n>3

expand 2 in 3

sort year

replace param1 = 0 if year == 2004 & year[_n-1]==2004
replace paramse1 = 0 if year == 2004 & year[_n-1]==2004
replace param2 = 0 if year == 2004 & year[_n-1]==2004
replace paramse2 = 0 if year == 2004 & year[_n-1]==2004
replace year = 2005 if year == 2004 & year[_n-1]==2004

replace paramse1 = sqrt(paramse1)
gen ci_up = param1 + (paramse1*1.64)
gen ci_low = param1 - (paramse1*1.64)

replace paramse2 = sqrt(paramse2)
gen ci_up2 = param2 + (paramse2*1.64)
gen ci_low2 = param2 - (paramse2*1.64)

gen year2 = year + 0.1

twoway (scatter param1 year, connect(l) color(gs4)) ///
(rcap ci_up ci_low year, color(gs4)) ///
(scatter param2 year2, connect(l) color(gs12)) ///
(rcap ci_up2 ci_low2 year2, color(gs12)), ///
xline(2005.5, lpattern(dash) lcolor(black)) ///
yline(0, lpattern(dash) lcolor(black)) ///
legend(order(1 3) label(1 "Any Muslim Exposure") label(3 "`ctitle'")) ///
xtitle(Year) graphregion(color(white)) ///
title(`title') ytitle(`ytitle')

graph export FigureA12_`var'_`set'.pdf, replace

local j = `j'+1
}
local k = `k'+1
}

restore

preserve
local titlelist " "Layers" "90-50 Wage Gap" "
local ytitlelist " "Number of Layers" "90-50 Log Wage Gap" "

foreach set in firmimpcomp firmimpcomplevel {
local j = 1
foreach var in layers loginequality4 {

local title : word `j' of `titlelist'
local ytitle : word `j' of `ytitlelist'

clear
estimates use "event_`var'_`set'"

matrix define lambda = e(b)
matrix define lambdase = e(V)

matrix lambdase2 = vecdiag(lambdase)

matrix param = [lambda[1,1..5]]'
matrix paramse = [lambdase2[1,1..5]]'
matrix param2 = [lambda[1,6..10]]'
matrix paramse2 = [lambdase2[1,6..10]]'

svmat param
svmat paramse
svmat param2
svmat paramse2

gen year = _n
replace year = year + 2001 if _n<=3
replace year = year + 2002 if _n>3

expand 2 in 3

sort year

replace param1 = 0 if year == 2004 & year[_n-1]==2004
replace paramse1 = 0 if year == 2004 & year[_n-1]==2004
replace param2 = 0 if year == 2004 & year[_n-1]==2004
replace paramse2 = 0 if year == 2004 & year[_n-1]==2004
replace year = 2005 if year == 2004 & year[_n-1]==2004

replace paramse1 = sqrt(paramse1)
gen ci_up = param1 + (paramse1*1.64)
gen ci_low = param1 - (paramse1*1.64)

replace paramse2 = sqrt(paramse2)
gen ci_up2 = param2 + (paramse2*1.64)
gen ci_low2 = param2 - (paramse2*1.64)

gen year2 = year + 0.1

twoway (scatter param1 year, connect(l) color(gs4)) ///
(rcap ci_up ci_low year, color(gs4)) ///
(scatter param2 year2, connect(l) color(gs12)) ///
(rcap ci_up2 ci_low2 year2, color(gs12)), ///
xline(2005.5, lpattern(dash) lcolor(black)) ///
yline(0, lpattern(dash) lcolor(black)) ///
legend(order(1 3) label(1 "Muslim Exposure") label(3 "China Exposure")) ///
xtitle(Year) graphregion(color(white)) ///
title(`title') ytitle(`ytitle')

graph export FigureA13_`var'_`set'.pdf, replace

local j = `j'+1
}
}

restore


* Importer Sample

xtset firmcode year
areg layers year2002-year2006 treatment_trend ///
Arab20052006 if year > 2000 & year < 2007 ///
& fullsample == 1, absorb(firmcode) vce(cluster sector027)

gen basesample = e(sample)==1
gen logimports = log(imports)

cap drop impsample
gen impsample = 1 if basesample==1 & logimports != . ///
& impshare_china != .

* Baseline
areg layers year2002-year2006 treatment_trend ///
Arab20052006 if year > 2000 & year < 2007 ///
& impsample == 1, absorb(firmcode) vce(cluster sector027)

outreg2 using TableA42.tex, ///
tex alpha(0.01, 0.05, 0.1) ///
symbol(***,**,*) bdec(4) keep(Arab20052006) ///
adds("Firms", e(df_a)+1) replace

* Control for import (competition) measures:

foreach var in logimports logimp_china impshare_china implevel_china {
* log(imports)
areg layers year2002-year2006 treatment_trend ///
Arab20052006 `var' if year > 2000 & year < 2007 ///
& impsample == 1, absorb(firmcode) vce(cluster sector027)

outreg2 using TableA42.tex, ///
tex alpha(0.01, 0.05, 0.1) ///
symbol(***,**,*) bdec(4) keep(Arab20052006) ///
adds("Firms", e(df_a)+1) append
}

**********************************
* Propensity to Delayer
**********************************
cd "${data_dir}"
use hierarchy_cartoon_data.dta, clear

cd "${results_dir}"

foreach var in layers log2inequality4 {
xtreg D.`var' ///
c.Arab20052001#c.shareexp#c.prdrop2005 ///
c.Arab20052002#c.shareexp#c.prdrop2005 ///
c.Arab20052003#c.shareexp#c.prdrop2005 ///
c.Arab20052004#c.shareexp#c.prdrop2005 ///
c.Arab20052006#c.shareexp#c.prdrop2005 ///
c.Arab20052007#c.shareexp#c.prdrop2005 ///
year2002-year2007 ///
Arab20052001 ///
Arab20052002 ///
Arab20052003 ///
Arab20052004 ///
Arab20052006 ///
Arab20052007 ///
c.Arab20052001#c.shareexp ///
c.Arab20052002#c.shareexp ///
c.Arab20052003#c.shareexp ///
c.Arab20052004#c.shareexp ///
c.Arab20052006#c.shareexp ///
c.Arab20052007#c.shareexp ///
2001.aar#c.prdrop2005 ///
2002.aar#c.prdrop2005 ///
2003.aar#c.prdrop2005 ///
2004.aar#c.prdrop2005 ///
2006.aar#c.prdrop2005 ///
2007.aar#c.prdrop2005 ///
if year > 2000 & year < 2008 ///
& prdropsample == 1 & L.layers >= 2, ///
fe vce(cluster sector027)

estimates save "event_prdrop_`var'", replace

outreg2 using TableA37.tex, ///
tex alpha(0.01, 0.05, 0.1) symbol(***,**,*) bdec(4) ///
keep(c.Arab20052001#c.shareexp#c.prdrop2005 ///
c.Arab20052002#c.shareexp#c.prdrop2005 ///
c.Arab20052003#c.shareexp#c.prdrop2005 ///
c.Arab20052004#c.shareexp#c.prdrop2005 ///
c.Arab20052006#c.shareexp#c.prdrop2005 ///
c.Arab20052007#c.shareexp#c.prdrop2005) ///
adds("Firms", e(df_a)+1) append

}

local i = 1
foreach var in layers log2inequality4 {
xtreg D.`var' ///
c.Arab20052001#c.shareexp#c.prdrop2005 ///
c.Arab20052002#c.shareexp#c.prdrop2005 ///
c.Arab20052003#c.shareexp#c.prdrop2005 ///
c.Arab20052004#c.shareexp#c.prdrop2005 ///
c.Arab20052006#c.shareexp#c.prdrop2005 ///
c.Arab20052007#c.shareexp#c.prdrop2005 ///
c.Arab20052008#c.shareexp#c.prdrop2005 ///
year2002-year2008 ///
Arab20052001 ///
Arab20052002 ///
Arab20052003 ///
Arab20052004 ///
Arab20052006 ///
Arab20052007 ///
Arab20052008 ///
c.Arab20052001#c.shareexp ///
c.Arab20052002#c.shareexp ///
c.Arab20052003#c.shareexp ///
c.Arab20052004#c.shareexp ///
c.Arab20052006#c.shareexp ///
c.Arab20052007#c.shareexp ///
c.Arab20052008#c.shareexp ///
2001.aar#c.prdrop2005 ///
2002.aar#c.prdrop2005 ///
2003.aar#c.prdrop2005 ///
2004.aar#c.prdrop2005 ///
2006.aar#c.prdrop2005 ///
2007.aar#c.prdrop2005 ///
2008.aar#c.prdrop2005 ///
if year > 2000 & year <= 2008 ///
& prdropsample == 1 & L.layers >= 2, ///
fe vce(cluster sector027)

estimates save "event_prdrop_`var'_long", replace

if `i' == 1 {
outreg2 using TableA39.tex, ///
tex alpha(0.01, 0.05, 0.1) symbol(***,**,*) bdec(4) ///
keep(c.Arab20052006#c.shareexp#c.prdrop2005 ///
c.Arab20052007#c.shareexp#c.prdrop2005 ///
c.Arab20052008#c.shareexp#c.prdrop2005) ///
adds("Firms", e(df_a)+1) append
}
local i = `i' + 1
}

* Add controls for exposure to the 2008 crisis:
* Financial leverage 2007
gen levhelp = totalleverage  if aar == 2007
cap drop leverage2007
bys cvrnr: egen leverage2007 = max(levhelp)
replace leverage2007 = 0 if leverage2007 == .
xtset firmcode_xt aar

set more off
local i = 1
foreach var in layers log2inequality4 {

xtreg D.`var'  ///
c.Arab20052001#c.shareexp#c.prdrop2005 ///
c.Arab20052002#c.shareexp#c.prdrop2005 ///
c.Arab20052003#c.shareexp#c.prdrop2005 ///
c.Arab20052004#c.shareexp#c.prdrop2005 ///
c.Arab20052006#c.shareexp#c.prdrop2005 ///
c.Arab20052007#c.shareexp#c.prdrop2005 ///
c.Arab20052008#c.shareexp#c.prdrop2005 ///
2001.aar#c.leverage2007#c.prdrop2005 ///
2002.aar#c.leverage2007#c.prdrop2005 ///
2003.aar#c.leverage2007#c.prdrop2005 ///
2004.aar#c.leverage2007#c.prdrop2005 ///
2006.aar#c.leverage2007#c.prdrop2005 ///
2007.aar#c.leverage2007#c.prdrop2005 ///
2008.aar#c.leverage2007#c.prdrop2005 ///
year2002-year2008 ///
Arab20052001 ///
Arab20052002 ///
Arab20052003 ///
Arab20052004 ///
Arab20052006 ///
Arab20052007 ///
Arab20052008 ///
c.Arab20052001#c.shareexp ///
c.Arab20052002#c.shareexp ///
c.Arab20052003#c.shareexp ///
c.Arab20052004#c.shareexp ///
c.Arab20052006#c.shareexp ///
c.Arab20052007#c.shareexp ///
c.Arab20052008#c.shareexp ///
2001.aar#c.prdrop2005 ///
2002.aar#c.prdrop2005 ///
2003.aar#c.prdrop2005 ///
2004.aar#c.prdrop2005 ///
2006.aar#c.prdrop2005 ///
2007.aar#c.prdrop2005 ///
2008.aar#c.prdrop2005 ///
2001.aar#c.leverage2007 ///
2002.aar#c.leverage2007 ///
2003.aar#c.leverage2007 ///
2004.aar#c.leverage2007 ///
2006.aar#c.leverage2007 ///
2007.aar#c.leverage2007 ///
2008.aar#c.leverage2007 ///
if year > 2000 & year <= 2008 & prdropsample == 1 & L.layers >= 2, ///
fe vce(cluster sector027)

estimates save "event_prdrop_`var'_ext1", replace

if `i' == 1 {
outreg2 using TableA39.tex, ///
tex alpha(0.01, 0.05, 0.1) symbol(***,**,*) bdec(4) ///
keep(c.Arab20052006#c.shareexp#c.prdrop2005 ///
c.Arab20052007#c.shareexp#c.prdrop2005 ///
c.Arab20052008#c.shareexp#c.prdrop2005) ///
adds("Firms", e(df_a)+1) append
}
local i = `i' + 1
}

* Export share of sales 2005:
cap drop exhelp
gen exhelp = vrd / sales_usd  if aar == 2005
replace exhelp = 1 if exhelp > 1 & exhelp != .
cap drop sharesales
bys cvrnr: egen sharesales = max(exhelp)
replace sharesales = 0 if sharesales == .
xtset firmcode_xt aar

foreach var in layers {

xtreg D.`var'  ///
c.Arab20052001#c.shareexp#c.prdrop2005 ///
c.Arab20052002#c.shareexp#c.prdrop2005 ///
c.Arab20052003#c.shareexp#c.prdrop2005 ///
c.Arab20052004#c.shareexp#c.prdrop2005 ///
c.Arab20052006#c.shareexp#c.prdrop2005 ///
c.Arab20052007#c.shareexp#c.prdrop2005 ///
c.Arab20052008#c.shareexp#c.prdrop2005 ///
2001.aar#c.sharesales#c.prdrop2005 ///
2002.aar#c.sharesales#c.prdrop2005 ///
2003.aar#c.sharesales#c.prdrop2005 ///
2004.aar#c.sharesales#c.prdrop2005 ///
2006.aar#c.sharesales#c.prdrop2005 ///
2007.aar#c.sharesales#c.prdrop2005 ///
2008.aar#c.sharesales#c.prdrop2005 ///
year2002-year2008 ///
Arab20052001 ///
Arab20052002 ///
Arab20052003 ///
Arab20052004 ///
Arab20052006 ///
Arab20052007 ///
Arab20052008 ///
c.Arab20052001#c.shareexp ///
c.Arab20052002#c.shareexp ///
c.Arab20052003#c.shareexp ///
c.Arab20052004#c.shareexp ///
c.Arab20052006#c.shareexp ///
c.Arab20052007#c.shareexp ///
c.Arab20052008#c.shareexp ///
2001.aar#c.prdrop2005 ///
2002.aar#c.prdrop2005 ///
2003.aar#c.prdrop2005 ///
2004.aar#c.prdrop2005 ///
2006.aar#c.prdrop2005 ///
2007.aar#c.prdrop2005 ///
2008.aar#c.prdrop2005 ///
2001.aar#c.sharesales ///
2002.aar#c.sharesales ///
2003.aar#c.sharesales ///
2004.aar#c.sharesales ///
2006.aar#c.sharesales ///
2007.aar#c.sharesales ///
2008.aar#c.sharesales ///
if year > 2000 & year <= 2008 & prdropsample == 1 & L.layers >= 2, ///
fe vce(cluster sector027)

estimates save "event_prdrop_`var'_ext2", replace

outreg2 using TableA39.tex, ///
tex alpha(0.01, 0.05, 0.1) symbol(***,**,*) bdec(4) ///
keep(c.Arab20052006#c.shareexp#c.prdrop2005 ///
c.Arab20052007#c.shareexp#c.prdrop2005 ///
c.Arab20052008#c.shareexp#c.prdrop2005) ///
adds("Firms", e(df_a)+1) append
}

* Add controls for exposure to the 2008 crisis:
* Share of exports in total sales 2007
cap drop exhelp
gen exhelp = vrd / sales_usd  if aar == 2007
replace exhelp = 1 if exhelp > 1 & exhelp != .
cap drop sharesales2007
bys cvrnr: egen sharesales2007 = max(exhelp)
replace sharesales2007 = 0 if sharesales2007 == .

* Muslim export share in 2007
cap drop exratiohelp
gen exratiohelp = Muslimtradevalue / vrd  if aar == 2007
cap drop shareexp2007
bys cvrnr: egen shareexp2007 = max(exratiohelp)
replace shareexp2007 = 0 if shareexp2007 == .
xtset firmcode_xt aar

foreach var in layers {

xtreg D.`var'  ///
c.Arab20052001#c.shareexp#c.prdrop2005 ///
c.Arab20052002#c.shareexp#c.prdrop2005 ///
c.Arab20052003#c.shareexp#c.prdrop2005 ///
c.Arab20052004#c.shareexp#c.prdrop2005 ///
c.Arab20052006#c.shareexp#c.prdrop2005 ///
c.Arab20052007#c.shareexp#c.prdrop2005 ///
c.Arab20052008#c.shareexp#c.prdrop2005 ///
c.Arab20052001#c.shareexp2007#c.prdrop2005 ///
c.Arab20052002#c.shareexp2007#c.prdrop2005 ///
c.Arab20052003#c.shareexp2007#c.prdrop2005 ///
c.Arab20052004#c.shareexp2007#c.prdrop2005 ///
c.Arab20052006#c.shareexp2007#c.prdrop2005 ///
c.Arab20052007#c.shareexp2007#c.prdrop2005 ///
c.Arab20052008#c.shareexp2007#c.prdrop2005 ///
c.Arab20052001#c.sharesales2007#c.prdrop2005 ///
c.Arab20052002#c.sharesales2007#c.prdrop2005 ///
c.Arab20052003#c.sharesales2007#c.prdrop2005 ///
c.Arab20052004#c.sharesales2007#c.prdrop2005 ///
c.Arab20052006#c.sharesales2007#c.prdrop2005 ///
c.Arab20052007#c.sharesales2007#c.prdrop2005 ///
c.Arab20052008#c.sharesales2007#c.prdrop2005 ///
year2002-year2008 ///
Arab20052001 ///
Arab20052002 ///
Arab20052003 ///
Arab20052004 ///
Arab20052006 ///
Arab20052007 ///
Arab20052008 ///
c.Arab20052001#c.shareexp ///
c.Arab20052002#c.shareexp ///
c.Arab20052003#c.shareexp ///
c.Arab20052004#c.shareexp ///
c.Arab20052006#c.shareexp ///
c.Arab20052007#c.shareexp ///
c.Arab20052008#c.shareexp ///
c.Arab20052001#c.shareexp2007 ///
c.Arab20052002#c.shareexp2007 ///
c.Arab20052003#c.shareexp2007 ///
c.Arab20052004#c.shareexp2007 ///
c.Arab20052006#c.shareexp2007 ///
c.Arab20052007#c.shareexp2007 ///
c.Arab20052008#c.shareexp2007 ///
c.Arab20052001#c.sharesales2007 ///
c.Arab20052002#c.sharesales2007 ///
c.Arab20052003#c.sharesales2007 ///
c.Arab20052004#c.sharesales2007 ///
c.Arab20052006#c.sharesales2007 ///
c.Arab20052007#c.sharesales2007 ///
c.Arab20052008#c.sharesales2007 ///
2001.aar#c.prdrop2005 ///
2002.aar#c.prdrop2005 ///
2003.aar#c.prdrop2005 ///
2004.aar#c.prdrop2005 ///
2006.aar#c.prdrop2005 ///
2007.aar#c.prdrop2005 ///
2008.aar#c.prdrop2005 ///
if year > 2000 & year <= 2008 & prdropsample == 1 & L.layers >= 2, ///
fe vce(cluster sector027)

estimates save "event_prdrop_`var'_ext3", replace

outreg2 using TableA39.tex, ///
tex alpha(0.01, 0.05, 0.1) symbol(***,**,*) bdec(4) ///
keep(c.Arab20052006#c.shareexp#c.prdrop2005 ///
c.Arab20052007#c.shareexp#c.prdrop2005 ///
c.Arab20052008#c.shareexp#c.prdrop2005) ///
adds("Firms", e(df_a)+1) append
}


* Pooled Results: Full sample
gen treat_exp = Arab20052006 * shareexp
gen year2006_prdrop2005 = (aar==2006)*prdrop2005
gen treat_prdrop2005 = Arab20052006 * prdrop2005
gen treat_exp_prdrop2005 = Arab20052006 * shareexp * prdrop2005

local i = 1
foreach var in layers log2inequality4 {

areg D.`var' year2002-year2006 year2006_prdrop2005 ///
Arab20052006 treat_exp treat_prdrop2005 treat_exp_prdrop2005 ///
if year > 2001 & year < 2007 ///
& prdropsample == 1 & L.layers >= 2, ///
absorb(firmcode) vce(cluster sector027)

testparm treat_prdrop2005 treat_exp_prdrop2005
local Ftest = r(F)
local pval = r(p)

outreg2 using Table7.tex, ///
tex alpha(0.01, 0.05, 0.1) symbol(***,**,*) bdec(4) ///
keep(year2006_prdrop2005 Arab20052006 treat_exp treat_prdrop2005 treat_exp_prdrop2005) ///
adds("Firms", e(df_a)+1, "F-test", `Ftest',"p-value", `pval') append

local i = `i' + 1
}

* Pooled Results, exclude outliers
foreach var in log2inequality1 log2inequality2 log2inequality4 ///
log2inequality5 wagegap3_topbottom_log {
sum `var' ///
if year >= 2001 & year < 2007 ///
& D.logsales_usd != . & D.layers != . & D.log2inequality4 !=. ///
& sample == 1 & L.layers >= 2, det

local low = r(p1)
local up = r(p99)

cap drop `var'_nooutlier
gen `var'_nooutlier = `var'
replace `var'_nooutlier = . if `var' < `low'
replace `var'_nooutlier = . if `var' > `up'
}

local i = 1
foreach var in log2inequality1 log2inequality2 log2inequality4 ///
log2inequality5 wagegap3_topbottom_log {

areg D.`var'_nooutlier year2002-year2006 year2006_prdrop2005 ///
Arab20052006 treat_exp treat_prdrop2005 treat_exp_prdrop2005 ///
if year > 2000 & year < 2007 ///
& prdropsample == 1 & L.layers >= 2, ///
absorb(firmcode_xt) vce(cluster sector027)

testparm treat_prdrop2005 treat_exp_prdrop2005
local Ftest = r(F)
local pval = r(p)

outreg2 using TableA46.tex, ///
tex alpha(0.01, 0.05, 0.1) symbol(***,**,*) bdec(4) ///
keep(year2006_prdrop2005 Arab20052006 treat_exp treat_prdrop2005 treat_exp_prdrop2005) ///
adds("Firms", e(df_a)+1, "F-test", `Ftest',"p-value", `pval') append

local i = `i' + 1
}



* Event Graphs:
***********************
preserve

local titlelist " "Layers" "90-50 Wage Gap" "
local ytitlelist " "Change in Number of Layers" "Change in 90-50 Wage Gap" "

local j = 1
foreach var in layers log2inequality4 {

local title : word `j' of `titlelist'
local ytitle : word `j' of `ytitlelist'

clear
estimates use "event_prdrop_`var'"

matrix define lambda = e(b)
matrix define lambdase = e(V)

matrix lambdase2 = vecdiag(lambdase)

matrix param = [lambda[1,1..6]]'
matrix paramse = [lambdase2[1,1..6]]'


svmat param
svmat paramse

gen year = _n
replace year = year + 2000 if _n<=4
replace year = year + 2001 if _n>4

expand 2 in 4

sort year

replace param1 = 0 if year == 2004 & year[_n-1]==2004
replace paramse1 = 0 if year == 2004 & year[_n-1]==2004
replace year = 2005 if year == 2004 & year[_n-1]==2004

replace paramse1 = sqrt(paramse1)
gen ci_up = param1 + (paramse1*1.64)
gen ci_low = param1 - (paramse1*1.64)

twoway (scatter param1 year, connect(l)) ///
(rcap ci_up ci_low year), ///
xline(2005.5, lpattern(dash) lcolor(black)) ///
yline(0, lpattern(dash) lcolor(black)) ///
legend(off) xtitle(Year) graphregion(color(white)) ///
title(`title') ytitle(`ytitle') xscale(range(2001(1)2007)) ///
xlabel(2001(2)2007)

graph export Figure4_`var'.pdf, replace

local j = `j'+1
}

restore

* Extended Event Study
preserve

local titlelist " "Layers" "90-50 Wage Gap" "
local ytitlelist " "Change in Number of Layers" "Change in 90-50 Wage Gap" "

local j = 1
foreach var in layers log2inequality4 {

local title : word `j' of `titlelist'
local ytitle : word `j' of `ytitlelist'

clear
estimates use "event_prdrop_`var'_long"

matrix define lambda = e(b)
matrix define lambdase = e(V)

matrix lambdase2 = vecdiag(lambdase)

matrix param = [lambda[1,1..7]]'
matrix paramse = [lambdase2[1,1..7]]'


svmat param
svmat paramse

gen year = _n
replace year = year + 2000 if _n<=4
replace year = year + 2001 if _n>4

expand 2 in 4

sort year

replace param1 = 0 if year == 2004 & year[_n-1]==2004
replace paramse1 = 0 if year == 2004 & year[_n-1]==2004
replace year = 2005 if year == 2004 & year[_n-1]==2004

replace paramse1 = sqrt(paramse1)
gen ci_up = param1 + (paramse1*1.64)
gen ci_low = param1 - (paramse1*1.64)

twoway (scatter param1 year, connect(l)) ///
(rcap ci_up ci_low year), ///
xline(2005.5, lpattern(dash) lcolor(black)) ///
yline(0, lpattern(dash) lcolor(black)) ///
legend(off) xtitle(Year) graphregion(color(white)) ///
title(`title') ytitle(`ytitle') xscale(range(2001(1)2007)) ///
xlabel(2001(2)2007)

graph export FigureA8_`var'.pdf, replace

local j = `j'+1
}

restore

* Extended Event Study, Controls for Financial Crisis


preserve

local titlelist " "Layers" "90-50 Wage Gap"  "
local ytitlelist " "Change in Number of Layers" "Change in 90-50 Log Wage Gap""

local j = 1

foreach var in layers log2inequality4 {

local title : word `j' of `titlelist'
local ytitle : word `j' of `ytitlelist'

clear
estimates use "event_prdrop_`var'_ext1"

matrix define lambda = e(b)
matrix define lambdase = e(V)

matrix lambdase2 = vecdiag(lambdase)

matrix param = [lambda[1,1..7]]'
matrix paramse = [lambdase2[1,1..7]]'
matrix param2 = [lambda[1,8..14]]'
matrix paramse2 = [lambdase2[1,8..14]]'

svmat param
svmat paramse
svmat param2
svmat paramse2

gen year = _n
replace year = year + 2000 if _n<=4
replace year = year + 2001 if _n>4

expand 2 in 4

sort year

replace param1 = 0 if year == 2004 & year[_n-1]==2004
replace paramse1 = 0 if year == 2004 & year[_n-1]==2004
replace param2 = 0 if year == 2004 & year[_n-1]==2004
replace paramse2 = 0 if year == 2004 & year[_n-1]==2004
replace year = 2005 if year == 2004 & year[_n-1]==2004

replace paramse1 = sqrt(paramse1)
gen ci_up = param1 + (paramse1*1.64)
gen ci_low = param1 - (paramse1*1.64)

replace paramse2 = sqrt(paramse2)
gen ci_up2 = param2 + (paramse2*1.64)
gen ci_low2 = param2 - (paramse2*1.64)

gen year2 = year + 0.1

twoway (scatter param1 year, connect(l) color(gs4)) ///
(rcap ci_up ci_low year, color(gs4)) ///
(scatter param2 year2, connect(l) color(gs12)) ///
(rcap ci_up2 ci_low2 year2, color(gs12)), ///
xline(2005.5, lpattern(dash) lcolor(black)) ///
yline(0, lpattern(dash) lcolor(black)) ///
legend(order(1 3) label(1 "Exposure to Cartoon Crisis") ///
label(3 "Financial Leverage in 2007")) ///
xtitle(Year) graphregion(color(white)) ///
title(`title') ytitle(`ytitle')

graph export FigureA9_`var'_ext1.pdf, replace

local j = `j'+1
}

restore

preserve

local titlelist " "Layers" "
local ytitlelist " "Change in Number of Layers" "

local j = 1

foreach var in layers {

local title : word `j' of `titlelist'
local ytitle : word `j' of `ytitlelist'

clear
estimates use "event_prdrop_`var'_ext2"

matrix define lambda = e(b)
matrix define lambdase = e(V)

matrix lambdase2 = vecdiag(lambdase)

matrix param = [lambda[1,1..7]]'
matrix paramse = [lambdase2[1,1..7]]'
matrix param2 = [lambda[1,8..14]]'
matrix paramse2 = [lambdase2[1,8..14]]'

svmat param
svmat paramse
svmat param2
svmat paramse2

gen year = _n
replace year = year + 2000 if _n<=4
replace year = year + 2001 if _n>4

expand 2 in 4

sort year

replace param1 = 0 if year == 2004 & year[_n-1]==2004
replace paramse1 = 0 if year == 2004 & year[_n-1]==2004
replace param2 = 0 if year == 2004 & year[_n-1]==2004
replace paramse2 = 0 if year == 2004 & year[_n-1]==2004
replace year = 2005 if year == 2004 & year[_n-1]==2004

replace paramse1 = sqrt(paramse1)
gen ci_up = param1 + (paramse1*1.64)
gen ci_low = param1 - (paramse1*1.64)

replace paramse2 = sqrt(paramse2)
gen ci_up2 = param2 + (paramse2*1.64)
gen ci_low2 = param2 - (paramse2*1.64)

gen year2 = year + 0.1

twoway (scatter param1 year, connect(l) color(gs4)) ///
(rcap ci_up ci_low year, color(gs4)) ///
(scatter param2 year2, connect(l) color(gs12)) ///
(rcap ci_up2 ci_low2 year2, color(gs12)), ///
xline(2005.5, lpattern(dash) lcolor(black)) ///
yline(0, lpattern(dash) lcolor(black)) ///
legend(order(1 3) label(1 "Exposure to Cartoon Crisis") ///
label(3 "Export Share of Sales")) ///
xtitle(Year) graphregion(color(white)) ///
title(`title') ytitle(`ytitle')

graph export FigureA9_`var'_ext2.pdf, replace

local j = `j'+1
}

restore


preserve

local titlelist " "Layers""
local ytitlelist " "Change in Number of Layers" "

local j = 1
foreach var in layers {

local title : word `j' of `titlelist'
local ytitle : word `j' of `ytitlelist'

clear
estimates use "event_prdrop_`var'_ext3"

matrix define lambda = e(b)
matrix define lambdase = e(V)

matrix lambdase2 = vecdiag(lambdase)


matrix param1 = [lambda[1,1..7]]'
matrix paramse1 = [lambdase2[1,1..7]]'
matrix param2 = [lambda[1,8..14]]'
matrix paramse2 = [lambdase2[1,8..14]]'
matrix param3 = [lambda[1,15..21]]'
matrix paramse3 = [lambdase2[1,15..21]]'

svmat param1
svmat paramse1
svmat param2
svmat paramse2
svmat param3
svmat paramse3

gen year = _n
replace year = year + 2000 if _n<=4
replace year = year + 2001 if _n>4

expand 2 in 4

sort year

replace param1 = 0 if year == 2004 & year[_n-1]==2004
replace paramse1 = 0 if year == 2004 & year[_n-1]==2004
replace param2 = 0 if year == 2004 & year[_n-1]==2004
replace paramse2 = 0 if year == 2004 & year[_n-1]==2004
replace param3 = 0 if year == 2004 & year[_n-1]==2004
replace paramse3 = 0 if year == 2004 & year[_n-1]==2004
replace year = 2005 if year == 2004 & year[_n-1]==2004

replace paramse1 = sqrt(paramse1)
gen ci_up = param1 + (paramse1*1.64)
gen ci_low = param1 - (paramse1*1.64)
replace paramse2 = sqrt(paramse2)
gen ci_up2 = param2 + (paramse2*1.64)
gen ci_low2 = param2 - (paramse2*1.64)
replace paramse3 = sqrt(paramse3)
gen ci_up3 = param3 + (paramse3*1.64)
gen ci_low3 = param3 - (paramse3*1.64)

gen year2 = year + 0.1
gen year3 = year + 0.2

twoway (scatter param1 year, connect(l) color(gs2)) ///
(rcap ci_up ci_low year, color(gs2)) ///
(scatter param2 year2, connect(l) color(gs8)) ///
(rcap ci_up2 ci_low2 year2, color(gs8)) ///
(scatter param3 year3, connect(l) color(gs12)) ///
(rcap ci_up3 ci_low3 year3, color(gs12)), ///
xline(2005.5, lpattern(dash) lcolor(black)) ///
yline(0, lpattern(dash) lcolor(black)) ///
legend(order(1 3 5) label(1 "Muslim Exports 2005") ///
label(3 "Muslim Exports 2007") label(5 "Export Share of Sales 2007")) ///
xtitle(Year) graphregion(color(white)) ///
title(`title') ytitle(`ytitle') xscale(range(2001(1)2007)) ///
xlabel(2001(2)2007)

graph export FigureA9_`var'_ext3.pdf, replace

local j = `j'+1
}

restore


*************************************************
* Worker-level results
*************************************************
cd "${data_dir}"
use workerdata_full.dta, clear

* add occupational layer information by worker
merge 1:1 aar pnr using workerdata_layer.dta, keepusing(layer)
* unmatched workers are unemployed
drop if _merge == 2
drop _merge

* add firm characteristics:
destring aar, replace
sort aar cvrnr
merge n:1 aar cvrnr using "hierarchy_IV_data",keepusing(sample nextadddrop layers)
tab aar _merge
drop if _merge == 2
drop _merge

merge n:1 aar cvrnr using "hierarchy_cartoon_data.dta",keepusing(treatment sample_v1)
tab aar _merge
drop if _merge == 2
drop _merge

* relevant sample period:
keep if aar >= 1999 & aar <= 2008

* keep workers adjacent to relevant jobs in the main sample
sort pnr aar
by pnr: gen prevsample = sample[_n-1] if aar==aar[_n-1]+1
keep if sample == 1 | prevsample == 1

cd "${results_dir}"

* analyze workers employed at firms that are most exposed to the boycott in 2005
*********************************************************************************
sort pnr aar

* Indicator for working at a boycott firm in 2005:
gen boycottfirmhelp = 0 
replace boycottfirmhelp = 1 if treatment == 1 & aar == 2005 & sample_v1 == 1
by pnr: egen boycottfirm = max(boycottfirmhelp)
tab aar boycottfirm

* Indicator for working at a firm in the sample in 2005:
sort pnr aar
by pnr: gen prevtreatment = treatment[_n-1] if aar==aar[_n-1]+1

gen age2 = age^2
gen age3 = age^3
gen age4 = age^4

set more off

forvalues x = 1999/2008 {
cap drop boycott_year`x'
gen boycott_year`x' = boycottfirm * (aar == `x')
}

* previous period variables:
by pnr: gen dwage = log(timelon) - log(timelon[_n-1]) if aar == aar[_n-1]+1
by pnr: gen prevcvrnr = cvrnr[_n-1] if aar == aar[_n-1]+1
by pnr: gen prevlbnr = lbnr[_n-1] if aar == aar[_n-1]+1
by pnr: gen prevlayer = layer[_n-1] if aar == aar[_n-1]+1

* next period variables:
by pnr: gen nextlayer = layer[_n+1] if aar == aar[_n+1]-1
by pnr: gen nextcvrnr = cvrnr[_n+1] if aar == aar[_n+1]-1

* Do I care what the worker who is hired has done before? I can simply compare wages!
gen new = prevcvrnr != cvrnr if cvrnr != ""
gen new2 = prevlbnr != lbnr if lbnr != ""
gen newjob = prevcvrnr != cvrnr & prevlbnr != lbnr ///
if cvrnr != "" & prevcvrnr != "" & lbnr != "" & prevlbnr != ""

set more off
cap drop demoted
gen demoted = prevlayer > layer if layer != . & prevlayer != .
cap drop nextdemoted
gen nextdemoted = layer > nextlayer if layer != . & nextlayer != .
gen unemployed = type == ""
gen exit = type == "" if prevcvrnr != "" & prevlbnr != ""
tab aar exit

set more off
sort pnr aar
* firm level:
by pnr: gen nextdrop = nextadddrop==-1
by pnr: gen prevnextdrop = nextdrop[_n-1] if aar == aar[_n-1]+1
by pnr: gen nextadd = nextadddrop==1
by pnr: gen prevnextadd = nextadd[_n-1] if aar == aar[_n-1]+1

replace experience = experience/1000
gen experience2 = experience^2
replace tenure = tenure/1000
gen tenure2 = tenure^2

egen firmcode = group(cvrnr) if cvrnr != ""
egen prevfirmcode = group(prevcvrnr) if prevcvrnr != ""

egen personcode = group(pnr)
xtset personcode aar

tab aar if prevtreatment != .
tab aar demoted if prevtreatment != .
tab aar exit if prevtreatment != .
tab aar newjob if prevtreatment != .
tab aar unemployed if prevtreatment != .

cap drop staydemoted
gen staydemoted = demoted if newjob == 0
cap drop movedemoted
gen movedemoted = demoted if newjob == 1

forvalues x = 1/4 {
gen postboycott_layer`x' = (aar==2006) * boycottfirm * (prevlayer==`x') if prevlayer != .
}

forvalues x = 1/4 {
gen postboycott_layer`x'_drop = (aar==2006) * boycottfirm * (prevlayer==`x') * (prevnextdrop==1) if prevlayer != .
}

cap log close
log using Table8_Avg20002005.txt, text replace

set more off
foreach var in dwage newjob unemployed {

tabstat `var' if aar >=2000 & aar <= 2005 & prevtreatment != ., stats(mean) by(prevlayer)
}
foreach var in demoted staydemoted movedemoted {

tabstat `var' if aar >=2000 & aar <= 2005 & prevtreatment != . & prevlayer >=2, stats(mean) by(prevlayer)
}

set more off
foreach var in dwage newjob unemployed {

tabstat `var' if aar >=2000 & aar <= 2005 & prevtreatment == 1, stats(mean) by(prevlayer)
}
foreach var in demoted staydemoted movedemoted {

tabstat `var' if aar >=2000 & aar <= 2005 & prevtreatment == 1 & prevlayer >=2, stats(mean) by(prevlayer)
}

log close

************************************
* Difference-in-Differences
************************************
set more off
foreach var in dwage newjob unemployed {

reg `var' i.aar#i.prevlayer i.prevlayer#c.boycottfirm ///
postboycott_layer1 postboycott_layer2 postboycott_layer3 postboycott_layer4 ///
i.educ i.gender age age2 age3 age4 L.tenure L.tenure2 ///
L.experience L.experience2 ///
L.i.layers if aar >=2000 & aar <= 2006 & prevtreatment != ., vce(robust)

outreg2 using Table8.tex, tex alpha(0.01, 0.05, 0.1) ///
symbol(***,**,*) bdec(4) ///
keep(postboycott_layer1 postboycott_layer2 postboycott_layer3 postboycott_layer4) append

}

foreach var in demoted staydemoted movedemoted {

reg `var' i.aar#i.prevlayer i.prevlayer#c.boycottfirm ///
postboycott_layer2 postboycott_layer3 postboycott_layer4 ///
i.educ i.gender age age2 age3 age4 L.tenure L.tenure2 ///
L.experience L.experience2 ///
L.i.layers if aar >=2000 & aar <= 2006 & prevtreatment != . & prevlayer >=2, vce(robust)

outreg2 using Table8.tex, tex alpha(0.01, 0.05, 0.1) ///
symbol(***,**,*) bdec(4) ///
keep(postboycott_layer2 postboycott_layer3 postboycott_layer4) append

}



*****************************************
* Logit Model
*****************************************
set more off
foreach var in newjob unemployed {

logit `var' i.aar#i.prevlayer i.prevlayer#c.boycottfirm ///
postboycott_layer1 postboycott_layer2 postboycott_layer3 postboycott_layer4 ///
i.educ i.gender age age2 age3 age4 L.tenure L.tenure2 ///
L.experience L.experience2 ///
L.i.layers if aar >=2000 & aar <= 2006 & prevtreatment != ., vce(robust) or

outreg2 using TableA47.tex, tex alpha(0.01, 0.05, 0.1) ///
symbol(***,**,*) bdec(4) adds(pseudo R2, e(r2_p)) ///
keep(postboycott_layer1 postboycott_layer2 postboycott_layer3 postboycott_layer4) append

}

set more off
foreach var in demoted staydemoted movedemoted {

logit `var' i.aar#i.prevlayer i.prevlayer#c.boycottfirm ///
postboycott_layer2 postboycott_layer3 postboycott_layer4 ///
i.educ i.gender age age2 age3 age4 L.tenure L.tenure2 ///
L.experience L.experience2 ///
L.i.layers if aar >=2000 & aar <= 2006 & prevtreatment != . & prevlayer >=2, vce(robust) or

outreg2 using TableA47.tex, tex alpha(0.01, 0.05, 0.1) ///
symbol(***,**,*) bdec(4) adds(pseudo R2, e(r2_p)) ///
keep(postboycott_layer2 postboycott_layer3 postboycott_layer4) append

}

****************************************************
* Counterfactual: Effect on Overall Inequality
****************************************************
reg dwage i.aar#i.prevlayer i.prevlayer#c.boycottfirm ///
postboycott_layer1 postboycott_layer2 postboycott_layer3 postboycott_layer4 ///
i.educ i.gender age age2 age3 age4 L.tenure L.tenure2 ///
L.experience L.experience2 ///
L.i.layers if aar >=2000 & aar <= 2006 ///
& prevtreatment != ., vce(robust)

gen wage_cf = log(timelon) ///
- _b[postboycott_layer1]*postboycott_layer1 ///
- _b[postboycott_layer2]*postboycott_layer2 ///
- _b[postboycott_layer3]*postboycott_layer3 ///
- _b[postboycott_layer4]*postboycott_layer4 if e(sample)==1

replace wage_cf = log(timelon) if e(sample)==0
gen wage_real = log(timelon) if wage_cf != .

log using Counterfactual_inequality.txt, text replace

* Actual and counterfactual wage inequality 2006 compared to 2005
tabstat wage_real wage_cf if aar <= 2006 & aar >= 2005, stats(N sd) by(aar)

* Share of employees working in boycotted firms in 2005 
* as share of total workforce
tab boycottfirm if aar == 2005 & wage_real != .
log close

